<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%!
   	// 提问
	String create(Input input, Token token) {
		Integer uid = token.getUid();
		Message msg = new Message(0);
		String title = filterIllegalCharacter(input.getDesc("title", ""));
		String content = filterIllegalCharacter(input.getDesc("content", ""));
		Integer aid = input.getInt("aid", -1);
		Integer gid = input.getInt("group", -1);
		if (title.length() < 3) {
			msg = new Message(-1, "标题长度不能少于3位哦");
			return msg.toJson();
		}
		if (title.length() > 20) {
			msg = new Message(-1, "标题长度不能大于20位哦");
			return msg.toJson();
		}
		if (content.length() < 3) {
			msg = new Message(-1, "内容长度不能少于3位哦");
			return msg.toJson();
		}
		if (content.length() > 2000) {
			msg = new Message(-1, "内容长度不能大于2000位哦");
			return msg.toJson();
		}
		Quest quest = new Quest();
		Integer hospital = input.getInt("hospital", -1);
		quest.setHospital(hospital);
		quest.setUid(uid);
		quest.setTitle(title);
		quest.setContent(content);
		quest.setAid(aid);
		quest.setGroupId(gid);
		String imgs = input.getDesc("imgs", "");
		quest.setImgs(JSONUtil.toJson(stringToList(imgs)));
		Integer id = (Integer)DBTools.db("basedb").addItem(quest);
		if (id == null) 
			msg = new Message(30041, "提问失败了");
		else 
			msg.put("data", id);
		return msg.toJson();
	}
%>
<%
    Tools.encryptPrint(out, create(input, token));
%>
